package com.wancaijinfu.parse;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

//import android.util.Log;






import android.util.Log;

import com.wancaijinfu.javabean.Repayment;

public class RepaymentParse  extends PostParse{

	@Override
	public Object parseSuccess(JSONObject object) throws JSONException {
		List<Repayment> data = new ArrayList<Repayment>();
		
		JSONArray repaymentList = object.getJSONArray("list");
		
		for (int i = 0; i < repaymentList.length(); i++) {
			JSONObject newObj = repaymentList.getJSONObject(i);
			Repayment item = new Repayment();
			item.id = newObj.getString("id");
		//	item.url = newObj.getString("url");
			item.captal = newObj.getDouble("capital");
			item.repay_time = newObj.getString("repay_time");
			item.interest = newObj.getDouble("interest");
			item.repayment_account = newObj.getDouble("repay_account");
			item.status  =  newObj.getString("status");
			calculate(item);
			
			data.add(item);
		}
		
		return data;
	}

	private static void calculate(Repayment item) {
		// TODO Auto-generated method stub
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
		String dateTime = df.format(Long.parseLong(item.repay_time+"000")); ;  
		//String sd = sdf.format(dateTime);
		String[] a = dateTime.split("-");
		
		item.year = Integer.parseInt(a[0]);
		item.month = Integer.parseInt(a[1]);
		item.day = Integer.parseInt(a[2]);
		Log.e("collectiontime", a[0]+a[1]+a[2]);
		
		
	}
	
	public static void main(String atgs[]){
		Repayment item = new Repayment();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
		item.repay_time="1446185090";;
		calculate(item);
		System.out.println(item.day);
		System.out.println(item.month);
		System.out.println(item.year);
	//	item.day
	
		//1446185090
	}	
		
		
	}
	

